package com.example.opengl_fbo;

import android.graphics.SurfaceTexture;
import android.opengl.GLSurfaceView;
import com.example.opengl_fbo.filter.CameraFilter;
import com.example.opengl_fbo.utils.LogUtil;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

public class LammyRender implements GLSurfaceView.Renderer {


   public LammyRender(GLSurfaceView glSurfaceView)
    {
        this.glSurfaceView = glSurfaceView;
        cameraInterface = new CameraInterface(glSurfaceView.getContext());


    }

    private GLSurfaceView glSurfaceView;
    private CameraInterface cameraInterface;
    private SurfaceTexture mSurfaceTexture;
    CameraFilter cameraFilter;

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        cameraFilter = new CameraFilter(glSurfaceView.getContext());
        cameraFilter.setCameraId("1");
        mSurfaceTexture = cameraFilter.getmSurfaceTexture();
        cameraInterface.setSurfaceTexture(mSurfaceTexture);
        LogUtil.e("start camera !");
        cameraInterface.openCamera();

    }

    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {
        cameraFilter.onSizeChanged(width , height);
    }

    @Override
    public void onDrawFrame(GL10 gl) {

        cameraFilter.draw();
    }

}
